//
//  TableView.swift
//  WebViewGoback
//
//  Created by 郑东喜 on 2017/2/23.
//  Copyright © 2017年 郑东喜. All rights reserved.
//

import UIKit

class TableView: UIViewController {
    
    //cell的重用标记
    fileprivate let cellReuserIdetifier = "cellID"
    
    ///dataSource
    lazy var dataSource: NSMutableArray = {
        let a : NSMutableArray = ["uiwebview","wkwebview"]
        return a
    }()
    
///tableView
    lazy var tableView: UITableView = {
        let y : UITableView = UITableView.init(frame: self.view.bounds)
        y.delegate = self;
        y.dataSource = self;
        return y
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        
        self.setUI()
    }
}

// MARK:- 设置UI
extension TableView {
    fileprivate func setUI() -> Void {
        self.view.addSubview(tableView)
    }
}

// MARK:- UITableViewDelegate,UITableViewDataSource
extension TableView : UITableViewDelegate,UITableViewDataSource {
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: self.cellReuserIdetifier)
        if cell == nil {
            cell = UITableViewCell(style: .default, reuseIdentifier: self.cellReuserIdetifier)
        }
        
        cell?.textLabel?.text = self.dataSource[indexPath.row] as? String
        
        return cell!
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataSource.count
    }
    
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        switch indexPath.row {
        case 0:
            
            self.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(ViewController(), animated: true)
            self.hidesBottomBarWhenPushed = false
            break
            
        case 1:
            self.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(WKViewController(), animated: true)
            self.hidesBottomBarWhenPushed = false
            break

        default:
            break
        }
    }
}

